<?php
/**
 * Created by Mauro Gadaleta
 * User: Mauro
 * Date: 12/04/11
 * Time: 12:20
 *
 * Gadget para imagenes
 */
class imageCMS extends gadgetsCMS {

    /**
     * @var string
     */
	public $template = 'image.tpl';

    /**
     * @var null|string
     */
	public $img = null;

    /**
     * @var array
     */
	public $size = array();

    /**
     * @var array
     */
	public $info = array();

    /**
     * @var array
     */
    public $actions = array();

    /**
     * Constructor set up
     * @param null $nameImage
     * @param string $path
     * @param int $viewScale
     */
	function __construct($nameImage = null, $path = "", $viewScale = 0) {
		parent::__construct();
		
		if(!is_null($nameImage) && $nameImage != "")
		{
			$this->img = $path.$nameImage;
			$this->setSizeImg();
		}
		
		if($viewScale != 0)
			$this->setScale($viewScale);
		else
			$this->assign('scale',0);
			
		$this->assign('img', $this);
        $this->assign('nameImage', $nameImage);
	}

    /**
     * Setea la escala a mostrar la imagen
     * @param  $scale
     * @return void
     */
	private function setScale($scale) {
		$this->assign('scale',$scale);
		$this->size['width'] = $this->size['width'] * $scale/100;
		$this->size['height'] = $this->size['height'] * $scale/100;
	}

    /**
     * Setea el tamaño de la imagen
     * @return void
     */
	private function setSizeImg() {
		$this->size = getimagesize($this->img);
		$this->size['height'] = $this->size[1];
		$this->size['width'] = $this->size[0];
		unset($this->size[0]);
		unset($this->size[1]);
	}

    /**
     * Setea el mensaje de información a mostrar debajo de la imagen
     * @param string $message
     * @return void
     */
	function setInfo($message = "") { $this->info[] = $message; }

    /**
     * Setea acciones para esa imagen
     * @param  $action
     * @param string $href
     * @param string $target
     * @param bool $confirm
     * @return void
     */
    function setAction($action, $href='', $target='', $confirm = false) {
        $this->actions[] = array(
            'name'      =>  $action,
            'href'      =>  $href,
            'target'    =>  $target,
            'confirm'   =>  $confirm
        );
    }
}
?>